//
//  DisplayImageViewController.swift
//  StealPicture
//
//  Created by ?! 郭斌勇 on 16/8/11.
//  Copyright © 2016年 ?! 郭斌勇. All rights reserved.
//

import UIKit

class DisplayImageViewController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {

    @IBOutlet weak var 图片展示CollectionView: UICollectionView!
    
    
    var 触发图片:图片信息_CL!{
        
        didSet{
            
            if let 解绑触发图片 = 触发图片 {
                内容类别 = 用途类别集合_全局量.获取内容类别根据图片(解绑触发图片)
            }
        }
        
    }
    
    var 内容类别:内容类别_CL?{
        
        didSet{
            
            if let 解绑内容类别 = 内容类别,
            let 解绑图片展示collectionView = 图片展示CollectionView{
                解绑图片展示collectionView.reloadData()
            }
        }
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        

    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        let 序号 = 内容类别?.成员id序号目录[触发图片.id!]
        图片展示CollectionView.scrollToItemAtIndexPath(NSIndexPath(forItem: 序号!, inSection: 0), atScrollPosition: .CenteredHorizontally, animated: false)

    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
        
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
    
    
    //MARK:UICollectionView代理
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
        
        return 内容类别!.成员集合.count;
        
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{
        
        let imageCell = collectionView.dequeueReusableCellWithReuseIdentifier("ImageCollectionViewCell", forIndexPath: indexPath) as! ImageCollectionViewCell
        imageCell.显示原图 = true
        imageCell.图片信息 = 内容类别?.成员集合[indexPath.item]
        return imageCell
        
    }
    
    
    
    
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
        return 图片展示CollectionView.bounds.size
    }
    
    

    

    @IBAction func 保存图片seg点击_函数(sender: UIButton) {
        self.performSegueWithIdentifier("DisplayImageViewController_返回", sender: sender)
    }
    

}
